Page({
  data: {
    value: 3,
    // 评论信息
    commentInfo: '',
    // 显示全部的有多少条信息
    count: 0,
    count1: 0,
    count2: 0,
    count3: 0,
    // 好评的数据
    praise: [],
    // 中评数据
    zhong: [],
    // 差评
    cha: []
  },

  onLoad: function () {
    
    wx.showLoading({
      title: '加载中',
    })
    const db = wx.cloud.database()
    const comment = db.collection('comment')
    comment.orderBy('comment', 'desc').get().then(res => {
      wx.hideLoading()
      console.log(res.data)
      this.setData({
        commentInfo: res.data,
        count: res.data.length
      })
      this.getPraise()
      this.getzhong()
      this.getCha()
    })
  },
  // 获取好评的评论
  getPraise: function () {
    // 存储好评信息的临时数组变量
    let lsbl = []
    // 循环查询推荐指数大于等于4的
    for (let i = 0; i < this.data.commentInfo.length; i++) {
      if (this.data.commentInfo[i].valueRate >= 4) {
        lsbl.push(this.data.commentInfo[i])
      }
    }
    console.log(lsbl)
    this.setData({
      praise: lsbl,
      count1: lsbl.length
    })
  },

  // 获取中评的评论
  getzhong: function () {
    // 存储好评信息的临时数组变量
    let lsbl = []
    // 循环查询推荐指数等于3的
    for (let i = 0; i < this.data.commentInfo.length; i++) {
      if (this.data.commentInfo[i].valueRate >= 2 && this.data.commentInfo[i].valueRate <= 3) {
        lsbl.push(this.data.commentInfo[i])
      }
    }
    console.log(lsbl)
    this.setData({
      zhong: lsbl,
      count2: lsbl.length
    })
  },
  // 获取差评的评论
  getCha: function () {
    // 存储好评信息的临时数组变量
    let lsbl = []
    // 循环查询推荐指数小于等于1的
    for (let i = 0; i < this.data.commentInfo.length; i++) {
      if (this.data.commentInfo[i].valueRate <= 1) {
        lsbl.push(this.data.commentInfo[i])
      }
    }
    console.log(lsbl)
    this.setData({
      cha: lsbl,
      count3: lsbl.length
    })
  }
});